package org.tigris.atlas.quizme.client.action;

import java.util.Collection;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.tigris.atlas.quizme.client.utils.Constants;
import org.tigris.atlas.quizme.service.QuizTopicCollectionServiceResponse;
import org.tigris.atlas.quizme.service.delegate.QuizServiceDelegate;
import org.tigris.atlas.quizme.service.delegate.ServiceDelegateFactory;

public class GetAllTopicsAction extends Action{
	public ActionForward execute(ActionMapping mapping, ActionForm form,
		      HttpServletRequest request, HttpServletResponse response) {	
		Collection topics = (Collection)request.getSession().getAttribute(Constants.ALL_TOPICS_KEY);
		if(topics == null){
			QuizServiceDelegate delegate = ServiceDelegateFactory.createQuizServiceDelegate();
			QuizTopicCollectionServiceResponse sdResponse = delegate.selectAllTopics();
			request.getSession().setAttribute(Constants.ALL_TOPICS_KEY,sdResponse.getQuizTopics());
		}
		return mapping.findForward("success");
	}
}
